package com.hoppinzq.test;

import org.htmlunit.WebClient;
import org.htmlunit.html.*;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.List;

/**
 * @author ZhangQi
 htmlhint遍历表格
 */
public class demo5 {

    @Test
    public void test1() throws IOException {
        final WebClient webClient = new WebClient();
        webClient.getOptions().setJavaScriptEnabled(true);
        webClient.getOptions().setThrowExceptionOnScriptError(false);
        final HtmlPage page = webClient.getPage("http://150.158.28.40:8811/index2.html");
        final HtmlTable table = page.getHtmlElementById("tickets");
        final HtmlTableHeader header = table.getHeader();
        final List<HtmlTableRow> headerRows = header.getRows();
        for(HtmlTableRow htmlTableRow:headerRows){
            for (final HtmlTableCell cell : htmlTableRow.getCells()) {
                System.err.print("  " + cell.asNormalizedText());
            }
        }
//        final HtmlTableFooter footer = table.getFooter();
//        final List<HtmlTableRow> footerRows = footer.getRows();
        System.err.println();
        for (final HtmlTableBody body : table.getBodies()) {
            final List<HtmlTableRow> rows = body.getRows();
            for(HtmlTableRow htmlTableRow:rows){
                for (final HtmlTableCell cell : htmlTableRow.getCells()) {
                    System.err.print("  " + cell.asNormalizedText());
                }
                System.err.println();
            }
        }
    }
}

